package com.uenpay.im.ui.old.activity.funds;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-3-22 下午6:56:47
 * @copyRight http://www.qiyunxin.com
 * @function 获取经费群余额信息
 */
public class GetFundsChatAmountInvokeItem extends BaseHttpInvokeItem {

	public class GetFundsChatAmountInvokeItemResult extends HttpInvokeResult {
		public String chatid;
		public String chatname;
		public int chattype;
		public String custid;
		public String amount;
		public String leftAmount;
		public int _isadmin;
	}

	public GetFundsChatAmountInvokeItemResult getOutPut() {
		return (GetFundsChatAmountInvokeItemResult) GetResultObject();
	}

	/**
	 * 获取经费群余额信息
	 * 
	 * @param chatid
	 */
	public GetFundsChatAmountInvokeItem(String chatid) {
		String url = APIConfiguration.getBaseUrl()
				+ "Chat/SpecialChat/getFundsChatAmount?chatid=" + chatid + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetFundsChatAmountInvokeItemResult result = new GetFundsChatAmountInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			if (json.has("data")) {
				JSONObject jsonData = json.optJSONObject("data");
				if (jsonData != null) {
					result.chatid = jsonData.optString("chatid");
					result.chatname = jsonData.optString("chatname");
					result.chattype = jsonData.optInt("chattype");
					result.custid = jsonData.optString("custid");
					result.amount = jsonData.optString("amount");
					result.leftAmount = jsonData.optString("leftAmount");
					result._isadmin = jsonData.optInt("_isadmin");
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return result;
	}

}
